home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 42 / Amiga Format AFCD42 (Issue 126, Aug 1999).iso / -serious- / emulation / onetouchmac / source / onetouchmac.c
C/C++ Source or Header  |  1999-05-14  |  3KB  |  87 lines

  1. // program:OneTouchMac V1.0
  2. // Author:TIPHAINE Julien
  3. // Last updated the: 30/04/1999
  4. // Description: Alow to execute a diferent startup-sequence, given in arguments,
  5. //              by pressing LMB or RMB. This prog ONLY WORK WITH AMIGA MOUSE PORT
  6.  
  7.  
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include <exec/types.h>
  11. #include <hardware/custom.h>
  12. #include <hardware/cia.h>
  13.  
  14.  
  15. #define LEFT_BUTTON   1
  16. #define MIDDLE_BUTTON 2
  17. #define RIGHT_BUTTON  4
  18.  
  19. #define PORT1 1
  20.  
  21. extern struct Custom far custom;
  22. extern struct CIA far ciaa;
  23.  
  24. /* here the Mouse function declaration, see below */
  25. UBYTE Mouse(UBYTE port, BYTE *delta_x, BYTE *delta_y);
  26.  
  27. int main(int argc, char **argv)
  28. {
  29.   UBYTE Reponse;
  30.   BYTE dx=0, dy=0;
  31.   char Commande[100]= "execute "; /* Just for executing files given in arguments */
  32.  
  33.   /* Check if some arguments have been typed */
  34.   if (argc < 2)
  35.    {   printf("Syntaxe is: OneTouchMac <Startup File 1> [<Startup File 2>]");
  36.        printf("\nTry Again ! :)");
  37.    }
  38.  
  39.   Reponse = Mouse (PORT1, &dx, &dy); /* get the Mouse button witch is pressed */
  40.  
  41.   /* First condition: Execute the first argument file if LMB is pressed */
  42.   if (Reponse == LEFT_BUTTON)
  43.    {   strcat(Commande, argv[1], argv[2]);
  44.        system(Commande);
  45.        return 1; /* Alow to stop Startup-sequence execution, that's why the first Startup-sequence comande mist be "FAILAT 1" */
  46.    }
  47.  
  48.   /* second condition: Execute the second argument file if RMB is pressed */
  49.   if (argc == 3) /* Test if a second Startup file has been typed */
  50.    {    if (Reponse == RIGHT_BUTTON)
  51.          {   strcat(Commande, argv[1], argv[3]);
  52.              system(Commande);
  53.              return 1;
  54.          }
  55.    }
  56.  
  57.   return 0; /* quit program if no mouse button is pressed */
  58.  
  59. }
  60.  
  61. /***************** Mouse Function ********************/
  62. /* Return values 1,2 or 4 if left, Middle or Right   */
  63. /* Mouse button have been pressed. the Middle mouse  */
  64. /* button is not yet used in this version...         */
  65. /* I know is not well programed at all, but sorry    */
  66. /* I have copied/pasted this function 'cause I didn't*/
  67. /* Know how to do this without opening a window...   */
  68. /* Sorry, but hey, I'm a Beginner !                  */
  69. /*****************************************************/
  70.  
  71. UBYTE Mouse(UBYTE port, BYTE *delta_x, BYTE *delta_y)
  72.   UBYTE data = 0;
  73.   UWORD joy, pot;
  74.  
  75.   custom.potgo = 0xFF00;
  76.   pot = custom.potinp;
  77.  
  78.   joy = custom.joy0dat;
  79.   data += !( ciaa.ciapra & 0x0040 ) ? LEFT_BUTTON : 0;
  80.   data += !( pot & 0x0100 ) ? MIDDLE_BUTTON : 0;
  81.   data += !( pot & 0x0400 ) ? RIGHT_BUTTON : 0;
  82.  
  83. return( data );
  84.  
  85. }
  86.